{{>head}}

<h1>Active Requests</h1>

<table id="tblActive" class="defTable">
	<thead>
		<tr>
			<th rowspan="2">id</th>
			<th rowspan="2">Last was</th>
			<th rowspan="2">Next Will</th>
			<th rowspan="2">Count</th>
			<th rowspan="2">Max</th>
			<th colspan="3" >Post To</th>
			<th rowspan="2">Actions</th>
		</tr>
		<tr>
			<th>File</th>
			<th><img src="templates/images/cvex.png" title="Cityville Exchange" height="20" /></th>
			<th><img src="templates/images/cvlinkex.png" title="Cityville Link Exchange" height="17" /></th>
		</tr>
	</thead>
	<tbody>
	{{#arMyReqs}}
		<tr>
			<td>
				<img src="{{imPath}}" width="30" align="middle" style="margin-right: 5px;" />
				{{showId}}
			</td>
			<td><small>{{lastWas}}</small></td>
			<td>
				<small>
				{{nextWill}}<br />
				{{nextTS}}
				</small>
			</td>
			<td>{{reqCount}}</td>
			<td>
				<input type="text" class="postUntilReach" value="{{maxWanted}}" />
			</td>
			<td><input type="checkbox" class="postToFile" {{postToFile}} /></td>
			<td><input type="checkbox" class="postToCVEx" {{postToCVEx}} /></td>
			<td><input type="checkbox" class="postToCVLinkEx" {{postToCVLinkEx}} /></td>
			<td>
				<a href="#" data-id="{{id}}" title="remove this" class="lnkRemove"></a>
				<a href="#" data-id="{{id}}" title="update this" class="lnkUpdate"></a>
			</td>			
		</tr>
	{{/arMyReqs}}
	</tbody>
</table>

<h1 style="margin-top:20px">Notes:</h1>
<ul>
	<li>File is Located in "tmp_dir/Wall2/"</li>
	<li>
		Max number is the number of how many requests will the plugin make. After this amount, the request will be removed. 
		If you dont want any limit, leave 0.
	</li>
</ul>
{{>foot}}

<script type="text/javascript">
	$(function(){
		
		$("#tblActive .lnkRemove").click(function(e){
			e.preventDefault();
			var $el = $(e.currentTarget);
			
			$.post("Main.php?act=removeRequest", $.toJSON( {"id": $el.attr("data-id")} ),
				function(r)
				{
					if (r.resp)
					{
						var $p = $el.parent().parent();
						$p.remove();
						return;
					}

					alert("oops");
				}
			,"json")
			.error(function() { alert("oops"); });
		});
		
		$("#tblActive .lnkUpdate").click(function(e){
			e.preventDefault();
			var $el = $(e.currentTarget);

			var $p = $el.parent().parent();
			
			var pData = $.toJSON({
				"id": $el.attr("data-id"),
				"postToFile"	: $p.find(".postToFile:first").is(":checked"),
				"postToCVEx"	: $p.find(".postToCVEx:first").is(":checked"),
				"postToCVLinkEx": $p.find(".postToCVLinkEx:first").is(":checked"),
				"maxWanted"		: $p.find(".postUntilReach:first").val()
			});
			
			$.post("Main.php?act=updateRequest",  pData,
				function(r)
				{
					if (r.resp)
					{
						$p.css({"backgroundColor":"#7fae8a"});
						setTimeout( function(){ $p.css({"backgroundColor":""}); },1000);
						return;
					}

					alert("oops");
				}
			,"json")
			.error(function() { alert("oops"); });
		});
	});
</script>